var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__spreadArrays) ||
        function () {
            for (var t = 0, e = 0, o = arguments.length; e < o; e++) t += arguments[e].length;
            var a = Array(t),
                i = 0;
            for (e = 0; e < o; e++) for (var n = arguments[e], r = 0, s = n.length; r < s; r++, i++) a[i] = n[r];
            return a;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("BaseSdkMode"),
    s = t("UIManager"),
    c = t("UIConfig"),
    p = t("GameEm"),
    l = t("GameCof"),
    d = (function (t) {
        i(e, t);
        function e() {
            return (null !== t && t.apply(this, arguments)) || this;
        }
        e.prototype.login = function () {
            cc.sys.platform == cc.sys.ANDROID &&
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "login", "()V");
        };
        e.prototype.init = function (t, e, o) {
            var a = this;
            this.loginResult = function (e) {
                console.log("登录回调信息", e.code);
                GameBaseManager.privacyIsOver = !0;
                if (1 == e.code) {
                    var o = l.default.accountPrefix + l.default.getLastId();
                    GameBaseManager.sendAndroidInit();
                    a.wkLogin(e.data.token, o, t);
                    GameBaseManager.startEnterGame = !0;
                    GameBaseManager.checkEnterZhuce();
                } else {
                    s.default.open(c.UIID.UIToast, {msg: "登录失败:" + e.data.msg});
                    a.login();
                }
            };
            this.payResult = function (t) {
                l.default.orderList = GameDataValue.getPropOrder();
                l.default.payIndex = l.default.orderList.length - 1;
                if (1 == t.code) {
                    console.log("支付成功", l.default.payIndex);
                    l.default.orderList[l.default.payIndex].status = 1;
                } else if (0 == t.code) {
                    console.log("支付失败", l.default.payIndex);
                    l.default.orderList[l.default.payIndex].status = -1;
                } else {
                    console.log("取消或者支付完成", l.default.payIndex);
                    if (l.default.orderList[l.default.payIndex].status > 0) {
                        l.default.orderList[l.default.payIndex].isReward = 1;
                        a.circleCheckOrder(
                            l.default.orderList[l.default.payIndex].orderNo,
                            0,
                            5,
                            1,
                            e,
                            l.default.payIndex
                        );
                    } else if (l.default.orderList[l.default.payIndex].status < 0) {
                        o && o();
                        l.default.orderList[l.default.payIndex].isReward = -1;
                    } else {
                        o && o();
                        a.circleCheckOrder(
                            l.default.orderList[l.default.payIndex].orderNo,
                            60,
                            5,
                            1,
                            function (t) {
                                a.reissueReward([t.data], !1);
                            },
                            l.default.payIndex
                        );
                    }
                    a.reportDataToOcean(
                        l.default.orderList[l.default.payIndex].pname,
                        l.default.orderList[l.default.payIndex].pid,
                        l.default.orderList[l.default.payIndex].status,
                        l.default.orderList[l.default.payIndex].amount
                    );
                    GameDataValue.setPropOrder("orders", l.default.orderList);
                }
                l.default.payEnd = !0;
            };
            cc.AndroidMange = this;
        };
        e.prototype.reportDataToOcean = function (t, e, o, a) {
            a *= 100;
            jsb.reflection.callStaticMethod(
                "org/cocos2dx/javascript/AppActivity",
                "payReport",
                "(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V",
                t,
                e,
                o,
                a
            );
        };
        e.prototype.circleCheckOrder = function (t, e, o, a, i, n, r) {
            var s = this;
            console.log("支付", "延迟时间", e);
            setTimeout(function () {
                s.updateOrderRewardStatus(
                    t,
                    function (c) {
                        if (1 != c.code) {
                            e *= 2;
                            if (a < o) {
                                a++;
                                console.log("支付", "奖励失败再来一次", JSON.stringify(c));
                                s.circleCheckOrder(t, e, o, a, i, n);
                            } else {
                                r && r();
                                console.log("支付", "放弃更新奖励状态：" + t);
                            }
                        } else {
                            console.log("支付", "更新奖励状态成功", JSON.stringify(c));
                            i && i(c);
                        }
                    },
                    function (t) {
                        r && r();
                        console.log("支付", "请求更新奖励状态失败", JSON.stringify(t));
                    }
                );
            }, 1e3 * e);
        };
        e.prototype.updateOrderRewardStatus = function (t, e, o) {
            try {
                var a = {orderno: t, token: l.default.token, gameid: l.default.gameid, channel: l.default.channel};
                GameBaseManager.requestJson(
                    l.default.notifyOrderRewardUrl,
                    function (t) {
                        console.log("支付", "完成", JSON.stringify(t));
                        e && e(t);
                    },
                    this,
                    "POST",
                    function (t) {
                        o && o(t);
                    },
                    a,
                    "application/json"
                );
            } catch (t) {
                console.log("支付", "更新奖励状态失败222", t.message);
            }
        };
        e.prototype.startAsynPay = function (t, e, o, a, i) {
            console.log("点击支付", e, t, o);
            var n = l.default.baseUrlV3 + l.default.baseLibPathV3 + l.default.pathOrder,
                r = {
                    pid: t,
                    price: o,
                    pname: e,
                    pnum: 1,
                    rewards: JSON.stringify(i),
                    token: l.default.token,
                    channel: l.default.channel
                };
            try {
                if (1 == l.default.payEnd) {
                    l.default.payEnd = !1;
                    l.default.orderList = GameDataValue.getPropOrder();
                    l.default.orderIndex = l.default.orderList.length;
                    GameBaseManager.requestJson(
                        n,
                        function (t) {
                            if (1 == t.code) {
                                console.log("支付", "发起购买", t.data.uid, t.data.orderno, l.default.orderIndex);
                                l.default.orderList[l.default.orderIndex] = {
                                    orderNo: t.data.orderno,
                                    status: 0,
                                    isReward: 0,
                                    rewards: i,
                                    pid: t.data.pid,
                                    pname: t.data.pname,
                                    amount: t.data.amount
                                };
                                GameDataValue.setPropOrder("orders", l.default.orderList);
                                jsb.reflection.callStaticMethod(
                                    "org/cocos2dx/javascript/AppActivity",
                                    "pay",
                                    "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
                                    t.data.orderno,
                                    t.data.uid,
                                    t.data.pid,
                                    t.data.pname,
                                    t.data.amount,
                                    t.data.channel
                                );
                            } else {
                                console.log("下单失败", JSON.stringify(t));
                                a && a();
                            }
                        },
                        this,
                        "POST",
                        function () {
                            console.log("下单失败", "请求下单失败");
                            a && a();
                        },
                        r,
                        "application/json"
                    );
                } else {
                    a && a();
                    console.log("上一笔订单未结束，不能下单");
                }
            } catch (t) {
                console.log("请求下单失败", t.message);
                a && a();
            }
        };
        e.prototype.wkLogin = function (t, e, o) {
            var a =
                l.default.baseUrlV3 +
                l.default.baseLibPathV3 +
                l.default.pathPlatformLogin2 +
                "?appid=1000000067&token=" +
                t +
                "&account=" +
                e +
                "&password=" +
                e +
                "&platform=" +
                l.default.platname +
                "&version=" +
                l.default.version +
                "&type=2&channel=" +
                l.default.channel +
                "&instime=" +
                l.default.gamecacheLoginType1Count +
                "&isclouds=" +
                l.default.isCloud;
            console.log("登录地址", a);
            "" != l.default.token
                ? o && o(l.default.token)
                : GameBaseManager.requestJson(
                      a,
                      function (t) {
                          if (1 == t.code) {
                              var e,
                                  a = t.data,
                                  i = a.token;
                              l.default.setLastLoginTime(a.lastlogintime);
                              console.log("登录", "订单", JSON.stringify(a.orders));
                              l.default.backOrders = a.orders;
                              l.default.setToken(i);
                              GameBaseManager.lastLoginTime = a.lastlogintime;
                              l.default.loginAccount2 = a.bindaccount;
                              l.default.UID = a.uid;
                              console.log("登录", "uid", l.default.UID);
                              o && o(l.default.token);
                              a.fcm;
                              e = t.data.storageVer || 0;
                              if (1 == l.default.isCloud) {
                                  var n = t.data.storageAry;
                                  if (!(n && n.length > 0)) {
                                      console.log("云存储", "从云上同步", "没有数据");
                                      return;
                                  }
                                  var r = {};
                                  if (e >= l.default.getLoginDataVersion())
                                      for (var s = 0; s < n.length; s++) {
                                          var c = n[s],
                                              p = c.StorageKey,
                                              d = c.contents;
                                          c.deadline, c.encryptStr;
                                          r[p] = d;
                                      }
                                  console.log("GameBaseManager ----------------- saveObj", JSON.stringify(r));
                                  l.default.addCloudCache(r);
                              }
                              l.default.setLoginVersion(e + 1);
                          } else console.log("后端登录失败了");
                      },
                      this,
                      "POST",
                      function () {
                          console.log("后端登录请求失败");
                      }
                  );
        };
        e.prototype.reissueReward = function (t, e) {
            var o = [],
                a = [],
                i = 0,
                r = "";
            if (t) {
                for (var s in t) {
                    t[s].things && (o = n(o, JSON.parse(t[s].things)));
                    a.push(t[s].orderno);
                    i += t[s].amount;
                    r += "," + t[s].orderno;
                }
                if (a.length <= 0) {
                    console.log("补发放", "不需要");
                    return;
                }
                console.log("所有奖励物品", JSON.stringify(o));
                var c = 0,
                    d = 0,
                    u = 0,
                    h = 0,
                    f = 0,
                    y = [],
                    v = 0;
                for (var g in o) {
                    if (1 == o[g].id) {
                        c += parseInt(o[g].num);
                        !o[g].pid || ("20032" != o[g].pid && "20031" != o[g].pid) || (v += parseInt(o[g].num));
                    }
                    6 == o[g].id && (d += parseInt(o[g].num));
                    7 == o[g].id && (u += parseInt(o[g].num));
                    if (4 == o[g].id) {
                        o[g].pid && "20161" == o[g].pid && (h += parseInt(o[g].num));
                        o[g].pid && "20162" == o[g].pid && (f += parseInt(o[g].num));
                    }
                    o[g].id > 4e3 && y.push(o[g].id);
                }
                if (h > 0)
                    for (g = 0; g < h; g++) {
                        console.log("发放月卡");
                        PayData.openMouth();
                    }
                if (f > 0)
                    for (g = 0; g < f; g++) {
                        console.log("发放周卡");
                        PayData.openWeak();
                    }
                if (c > 0) {
                    console.log("发放砖石", c);
                    GameDataValue.setPropCount(
                        p.PropKind.zhuanshi,
                        GameDataValue.getPropCount(p.PropKind.zhuanshi) + c
                    );
                }
                if (y.length > 0)
                    for (var m in y) {
                        console.log("发放装个逼", y[m]);
                        GameDataValue.addEquip(y[m]);
                    }
                if (v > 0) {
                    console.log("发放扣掉猪猪银行", v);
                    PayData.addPropZs(-v);
                }
                if (d > 0) {
                    console.log("发放普通要是", d);
                    GameDataValue.setShopKey("6", GameDataValue.getShopKey("6") + d);
                }
                if (u > 0) {
                    console.log("发放豪华要是", u);
                    GameDataValue.setShopKey("7", GameDataValue.getShopKey("7") + u);
                }
                console.log("发放完毕", "更改订单装填");
                CacheDataManager.updateCostDataView = !0;
                if (e) {
                    var _ = {
                        ordernos: JSON.stringify(a),
                        token: l.default.token,
                        gameid: l.default.gameid,
                        channel: l.default.channel
                    };
                    GameBaseManager.requestJson(
                        l.default.notifyOrdersRewardUrl,
                        function (t) {
                            console.log("支付", "更新了奖励状态", JSON.stringify(t));
                        },
                        this,
                        "POST",
                        function (t) {
                            console.log("支付", "更新奖励状态失败", JSON.stringify(t));
                        },
                        _,
                        "application/json"
                    );
                }
                console.log("发放", "上报日志");
                var C = {resId: "300000", count: i, type: 2, tip: "订单补发物品", tip2: "订单号" + r};
                PayData.addLog(C.resId, C.count, C.type, o, C.tip, C.tip2);
            }
        };
        e.prototype.reportDataToWk = function (t, e, o) {
            jsb.reflection.callStaticMethod(
                "org/cocos2dx/javascript/AppActivity",
                "reportData",
                "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
                t,
                e,
                o
            );
        };
        return e;
    })(r.default);
o.default = d;
